//
//  UIViewControllerExtensions.swift
//  Fangxukanghan
//
//  Created by 常超群的MacBookPro on 2021/7/16.
//

import UIKit

public extension UIViewController {
    // MARK: - 找到当前显示的viewcontroller
    class func ccq_currentVC(base: UIViewController? = UIApplication.shared.ccq_currentWindow?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return ccq_currentVC(base: nav.visibleViewController)
        }
        if let tab = base as? UITabBarController {
            return ccq_currentVC(base: tab.selectedViewController)
        }
        if let presented = base?.presentedViewController {
            return ccq_currentVC(base: presented)
        }
        if let split = base as? UISplitViewController{
            return ccq_currentVC(base: split.presentingViewController)
        }
        return base
    }
}
